import axios from 'axios';

const instance = axios.create({
    baseURL: "http://192.168.113.249:8081/cms"
})

//请求拦截器
instance.interceptors.request.use(config => {
    let token = localStorage.getItem("x-auth-token");
    if (token) {
        config.headers["x-auth-token"] = token;
    }
    console.log("请求拦截器...");
    return config;
}, error => {
    return Promise.reject(error);
})

//响应拦截器
instance.interceptors.response.use(response => {
    console.log("响应拦截器...");
    if (response.data.code != 0 && response.data.code != 407 && response.data.code != 400) {
        alert(response.data.message)
        return
    }
    return response.data;
}, error => {
    return Promise.reject(error);
})

export default instance;